<?php
session_start();
try
{
	//Open database connection
	$con = mysql_connect("localhost","root","555");
	mysql_select_db("mlm", $con);

	//Getting records (listAction)
	if($_GET["action"] == "list")
	{
        $ParentNumber = $_GET["ParentNumber"];
		//Get records from database
		$result = mysql_query("
            select 
                id, (concat(number, ' - ', LastName, ' ', substr(name, 1, 1), '. ', substr(MiddleName, 1, 1), '. ')) fio 
            from users where ParentNumber = ". $ParentNumber ."           
         ;");
		
		//Add all records to an array
        $i = 0;
		$rows = array();
		while($row = mysql_fetch_array($result))
		{
		    $rows[$i]['DisplayText'] = $row[1];
            $rows[$i]['Value'] = $row[0];
            $i++;
		}

		//Return result to jTable
		$jTableResult = array();
		$jTableResult['Result'] = "OK";
		$jTableResult['Options'] = $rows;
		print json_encode($jTableResult);
	}


	//Close database connection
	mysql_close($con);

}
catch(Exception $ex)
{
    //Return error message
	$jTableResult = array();
	$jTableResult['Result'] = "ERROR";
	$jTableResult['Message'] = $ex->getMessage();
	print json_encode($jTableResult);
}
	
?>
